package com.wego.controller.admin;

import com.wego.bean.PageBean;
import com.wego.bean.ResultBean;
import com.wego.converter.GameCategoryConverter;
import com.wego.domain.details.GameCategoryDetails;
import com.wego.domain.dto.GameCategoryDTO;
import com.wego.domain.entity.GameCategory;
import com.wego.domain.query.GameCategoryQuery;
import com.wego.domain.vo.GameCategoryVO;
import com.wego.service.GameCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 游戏分类(tb_gameCategory)表控制层
 *
 */
@RestController
@RequestMapping("/admin/gameCategory")
public class AdminGameCategoryController {
    @Autowired
    private GameCategoryService gameCategoryService;
    @Autowired
    private GameCategoryConverter gameCategoryConverter;


    @GetMapping("/page")
    public ResultBean<PageBean<GameCategoryVO>> page(GameCategoryQuery gameCategoryQuery) {
        final PageBean<GameCategory> gameCategoryPageBean = gameCategoryService.getPage(gameCategoryQuery);
        final PageBean<GameCategoryVO> pageBean = gameCategoryConverter.entityPageBean2voPageBean(gameCategoryPageBean);
        return ResultBean.success(pageBean);
    }

    @GetMapping("/{id}")
    public ResultBean<GameCategoryDetails> getDetails(@PathVariable("id") Integer id) {
        final GameCategory gameCategory = gameCategoryService.getById(id);
        final GameCategoryDetails gameCategoryDetails = gameCategoryConverter.gameCategory2gameCategoryDetails(gameCategory);
        return ResultBean.success(gameCategoryDetails);
    }

    @GetMapping("/all")
    public ResultBean<List<GameCategory>> list() {
        final List<GameCategory> gameCategoryList = gameCategoryService.getAll();

        return ResultBean.success(gameCategoryList);
    }

    @PutMapping
    public ResultBean<Void> update(@RequestBody GameCategoryDTO gameCategoryDTO) {
        final GameCategory gameCategory = gameCategoryConverter.dto2entity(gameCategoryDTO);
        gameCategoryService.update(gameCategory);
        return ResultBean.success("修改成功!", null);
    }

    @PostMapping
    public ResultBean<Void> insert(@RequestBody GameCategoryDTO gameCategoryDTO) {
        final GameCategory gameCategory = gameCategoryConverter.dto2entity(gameCategoryDTO);
        gameCategoryService.insert(gameCategory);
        return ResultBean.success("添加成功!", null);
    }
    @DeleteMapping
    public ResultBean<Void> batchDelete(@RequestParam List<Integer> ids) {
        gameCategoryService.deleteByIds(ids);
        return ResultBean.success("批量删除成功!", null);
    }

}
